package com.aidex.biz.controller;

import com.aidex.biz.domain.CockpitInfo;
import com.aidex.biz.service.CockpitInfoService;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.PageDomain;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.poi.ExcelUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 驾驶舱信息Controller
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/biz/bizCockpitInfo")
public class CockpitInfoController extends BaseController {
    @Autowired
    private CockpitInfoService cockpitInfoService;

    /**
     * 查询驾驶舱信息列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:list')")
    @GetMapping("/list")
    public R<PageInfo> list(CockpitInfo cockpitInfo, HttpServletRequest request, HttpServletResponse response) {
        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            cockpitInfo.setCompanyId(null);
        } else {
            cockpitInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        cockpitInfo.setPage(new PageDomain(request, response));
        return R.data(cockpitInfoService.findPage(cockpitInfo));
    }

    /**
     * 查询驾驶舱信息列表
     */
    @GetMapping("/findList")
    public R findList(CockpitInfo cockpitInfo, HttpServletRequest request, HttpServletResponse response) {
        List<CockpitInfo> list = cockpitInfoService.findList(cockpitInfo);
        return R.data(list);
    }

    /**
     * 获取驾驶舱信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:query')")
    @GetMapping(value = "/{id}")
    public R<CockpitInfo> detail(@PathVariable("id") String id) {
        return R.data(cockpitInfoService.get(id));
    }

    /**
     * 新增驾驶舱信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:add')")
    @Log(title = "驾驶舱信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated CockpitInfo cockpitInfo) {
        return R.status(cockpitInfoService.save(cockpitInfo));
    }

    /**
     * 修改驾驶舱信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:edit')")
    @Log(title = "驾驶舱信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated CockpitInfo cockpitInfo) {
        return R.status(cockpitInfoService.save(cockpitInfo));
    }


    /**
     * 删除驾驶舱信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:remove')")
    @Log(title = "驾驶舱信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(cockpitInfoService.deleteCockpitInfoByIds(ids));
    }

    /**
     * 获取最大编号
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort() {
        return R.data(cockpitInfoService.findMaxSort(new CockpitInfo()));
    }

    /**
     * 导出驾驶舱信息列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:bizCockpitInfo:export')")
    @Log(title = "驾驶舱信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(CockpitInfo cockpitInfo) {

        if (SecurityUtils.isAdmin(SecurityUtils.getUserId())) {
            cockpitInfo.setCompanyId(null);
        } else {
            cockpitInfo.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
        }
        List<CockpitInfo> list = cockpitInfoService.findList(cockpitInfo);
        ExcelUtil<CockpitInfo> util = new ExcelUtil<CockpitInfo>(CockpitInfo.class);
        return util.exportExcel(list, "驾驶舱信息数据");
    }

}
